﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GcmpModelInterface.h"

namespace gcmp
{
    // \brief Gcmp初始化和反初始化操作
    class GCMP_MODEL_INTERFACE_EXPORT GcmpEnvironment
    {
    public:
        /// \brief 获取环境实例
        /// \return 环境实例
        static GcmpEnvironment * Get();

        /// \brief Gcmp初始化操作
        /// \param arguments 传入的命令行参数
        /// \return void
        static void Initialize(const std::vector<std::wstring>& arguments);

        /// \brief Gcmp反初始化操作
        /// \return void
        static void Uninitialize();

        /// \brief 是否是构件级协同环境
        /// \return 是-true；否-false
        static bool IsInElementCollaborationEnvironment();

        /// \brief 获取选中的环境
        /// \return 环境字符串
        const std::wstring& Selected() const;
    public:
        /// \brief 选择环境
        /// \param environment 环境设定字符串
        /// \return 是否选择成功
        virtual bool Select(const std::wstring & environment) = 0;

        /// \brief 析构函数
        virtual ~GcmpEnvironment() = 0;

    protected:
        static GcmpEnvironment * s_environmentInstance;
        std::wstring m_environment;
        bool m_bEntCollaboration = { false };
    };

    /// \brief Gcmp自动环境切换器
    class GCMP_MODEL_INTERFACE_EXPORT GcmpEnvironmentAutoShifter
    {
    public:
        /// \brief 构造
        /// \param environment 选择的新环境
        GcmpEnvironmentAutoShifter(const std::wstring & environment);

        /// \brief 析构
        /// 
        /// 此时切换回之前的环境
        ~GcmpEnvironmentAutoShifter();
    private:
        std::wstring m_oldEnv;
        bool m_shifted;
    };
}

#define IN_ELEMENT_COLLABORATION_ENV() gcmp::GcmpEnvironment::IsInElementCollaborationEnvironment()
